module ListAssoco (ListAssoc,
		la_empty,
		la_add,
		la_search,
		la_del,
		la_toListPair
		)
where

data ListAssoc a b = Node a b (ListAssoc a b) | Empty
	deriving Show
	
la_empty :: ListAssoc a b
la_empty = Empty

la_add :: Ord a => ListAssoc a b -> a -> b -> ListAssoc a b
la_add Empty x y = Node x y Empty
la_add l@(Node a b xs) x y	|x == a = l
				|x < a = Node x y l
				|x > a = Node a b (la_add xs x y)
				

la_search :: Eq a => ListAssoc a b -> a -> Maybe b
la_search Empty x = Nothing
la_search (Node x y xs)	m |m == x = Just y
			  |otherwise = la_search xs m
			  
la_del :: Eq a => ListAssoc a b -> a -> ListAssoc a b
la_del Empty m = Empty
la_del (Node x y xs) m	|m == x = xs
			|otherwise = Node x y (la_del xs m)
			
la_toListPair :: ListAssoc a b -> [(a,b)]
la_toListPair Empty = []
la_toListPair (Node x y xs) = (x,y) : la_toListPair xs
